package com.djzhou.flow.service.impl;

import java.util.HashMap;
import java.util.List;

import com.djzhou.flow.model.FlowWorkFlowAudit;
import com.djzhou.flow.service.WorkFlowAuditService;
import com.djzhou.gmms.model.entity.PageBean;
import com.djzhou.gmms.model.user.VoResource;

public class WorkFlowAuditServiceImpl extends BaseFlowServiceImpl implements WorkFlowAuditService {

	@Override
	public void add(FlowWorkFlowAudit t) {
		workFlowAuditDAO.insert(t);
	}

	@Override
	public void update(FlowWorkFlowAudit t) {
		workFlowAuditDAO.update(t);
	}

	@Override
	public void delete(Integer id) {
		FlowWorkFlowAudit workFlow=workFlowAuditDAO.queryByID(FlowWorkFlowAudit.class, id);
		if(workFlow!=null)
			workFlowAuditDAO.delete(workFlow);
	}

	@Override
	public PageBean<FlowWorkFlowAudit> queryPageBean(HashMap<String, Object> hashMap,
			int pageSize, int currentPage) {
		String hql="from FlowWorkFlowAudit workFlow where 1=1";
		StringBuffer sb=new StringBuffer();
		sb.append(hql);
		if(hashMap!=null && hashMap.size()!=0){
			if(hashMap.get("role")!=null){
				sb.append(" and workFlow.role.roleName like '%").append(hashMap.get("role").toString()+"%'");
			}
			if(hashMap.get("auditRole")!=null){
				sb.append(" and workFlow.auditRoleNames like '%").append(hashMap.get("auditRole").toString()+"%'");
			}
			if(hashMap.get("workFlowClass")!=null){
				sb.append(" and workFlow.workFlowClass like '%").append(hashMap.get("workFlowClass").toString()+"%'");
			}
		}
		sb.append(" order by workFlow.workFlowClass");
		hql=sb.toString();
		PageBean<FlowWorkFlowAudit> pageBean=workFlowAuditDAO.selectByPage(hql, pageSize, currentPage);
		return pageBean;
	}
	
	@Override
	public List<FlowWorkFlowAudit> queryList(HashMap<String, Object> hashMap) {
		String hql="from FlowWorkFlowAudit";
		return workFlowAuditDAO.query(hql);
	}
	
	@Override
	public FlowWorkFlowAudit queryById(Integer id) {
		return workFlowAuditDAO.queryByID(FlowWorkFlowAudit.class, id);
	}
	
	@Override
	public List<FlowWorkFlowAudit> queryListBySource(String workFlowClass,int sourceId) {
		String hql="from FlowWorkFlowAudit where workFlowClass='"+workFlowClass+"' and sourceId=" + sourceId;
		return workFlowAuditDAO.query(hql);
	}
	
	@Override
	public void deleteAuditSource(String workFlowClass,int sourceId){
		String hql="delete from FlowWorkFlowAudit where workFlowClass='"+workFlowClass+"' and sourceId=" + sourceId;
		workFlowAuditDAO.delete(hql);
	}

	@Override
	public VoResource query4AutoComplete(HashMap<String, Object> hashMap, String sidx,
			String sord, int pageSize, int currentPage) {
		return null;
	}

}
